package com.lds.offer.demo;

/**
 * @description: Offer 05. 替换空格
 * @author: lds
 * @create: 2022-10-17 17:15
 **/
public class Offer_05_替换空格 {

    //https://leetcode.cn/problems/ti-huan-kong-ge-lcof/

    public static void main(String[] args) {
        String s = replaceSpace(" aaa b ");
        System.out.println(s);
    }

    public static String replaceSpace(String s) {
        StringBuilder builder = new StringBuilder();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == ' ') {
                builder.append("%20");
            } else {
                builder.append(chars[i]);
            }
        }
        return builder.toString();
    }
}
